package com.fengke.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.fengke.dao.cache.CacheManager;
import com.fengke.payment.tencent.common.RestHttpRequestHelper;
import com.fengke.service.CacheService;
import com.fengke.util.Constants;

public class CacheServiceImpl implements CacheService {
	private CacheManager cacheManager;
	
	@Override
	public void invalidCache(String cacheModelId) throws Exception {
		cacheManager.invalidCache(cacheModelId);
	}
	
	private void invalidMachineCache(Map<String, String> paramMap) {
		RestHttpRequestHelper.executeHttpRequest(Constants.CacheInfo.CACHE_URL_ESTORE, paramMap);
		RestHttpRequestHelper.executeHttpRequest(Constants.CacheInfo.CACHE_URL_AGENT, paramMap);
	}
	
	@Override
	public void invalidProductCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_PRODUCT);
		invalidMachineCache(paramMap);
	}

	@Override
	public void invalidDivisionCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_DIVISION);
		invalidMachineCache(paramMap);
	}
	
	@Override
	public void invalidMemberCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_MEMBER);
		invalidMachineCache(paramMap);
	}
	
	@Override
	public void invalidAdminCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_ADMIN);
		invalidMachineCache(paramMap);
	}
	
	@Override
	public void invalidMasterCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_MASTER);
		invalidMachineCache(paramMap);
	}
	
	@Override
	public void invalidTagCache() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("cacheId", Constants.CacheInfo.CACHE_ID_TAG);
		invalidMachineCache(paramMap);
	}

	public CacheManager getCacheManager() {
		return cacheManager;
	}

	public void setCacheManager(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}
}
